﻿using UnityEngine;
using System.Collections;

public class BackInputReceiver : MonoBehaviour {
    Camera cameraUI
    {
        get
        {
            if (cachUICamera != null)
            {
                return cachUICamera;
            }
            else
            {
                cachUICamera = UICamera.current.cachedCamera;
                return cachUICamera;
            }
        }
    }
    private Camera cachUICamera;

    public SimpleGrid simpleGrid;

    public void OnClick()
    {
        if(NGUITools.GetActive(simpleGrid))
        {
            Vector3 wp = cameraUI.ScreenToWorldPoint(Input.mousePosition);
            simpleGrid.OnClickX(wp);
        }
    }

	public void OnDrag(Vector2 delta)
	{
        if (NGUITools.GetActive(simpleGrid))
        {
            Vector3 wp = cameraUI.ScreenToWorldPoint(Input.mousePosition);
            simpleGrid.OnDragX(wp, delta);
        }
	}

    public void OnPress(bool isPress)
    {
        if (NGUITools.GetActive(simpleGrid))
        {
            Vector3 wp = cameraUI.ScreenToWorldPoint(Input.mousePosition);
            simpleGrid.OnPressX(wp, isPress);
        }
    }
}
